﻿using System;

namespace Quail.DbLogger.Task
{
	/// <summary>
	/// Wraps inserting a new TestRunTaskLogEntry
	/// </summary>
    public class InsertTestRunLogEntry : QuailDbLoggerEntry
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="InsertTestRunLogEntry"/> class.
        /// </summary>
        /// <param name="testruntaskid">The testruntaskid.</param>
        /// <param name="entrystatus">The entrystatus.</param>
        /// <param name="url">The current url.</param>
        /// <param name="message">The message.</param>
        /// <param name="createDate">Time the log entry was created</param>
        public InsertTestRunLogEntry(long testruntaskid, LogStatus entrystatus, string url, string message, DateTime createDate)
        {
            EntryCreateDate = createDate;
            TestRunTaskId = testruntaskid;
            EntryStatus = entrystatus;
            Url = url;
            Message = message;
        }

        private long TestRunTaskId { get; set; }

        private LogStatus EntryStatus { get; set; }

        private string Url { get; set; }

        private string Message { get; set; }

        private DateTime EntryCreateDate { get; set; }

        /// <summary>
        /// Inserts a new text run log entry
        /// </summary>
        /// <param name="dataContext">the context to use</param>
        public override void Store(QuailServices.QuailDataServiceReference.QuailDataServiceClient dataContext)
        {
            var testRunTaskLogEntryId = dataContext.InsertTestRunTaskLogEntry(TestRunTaskId, (int)EntryStatus, Url, Message, EntryCreateDate);
        }

        /// <summary>
        /// Returns a string representation of the entry for logging purposes
        /// </summary>
        /// <returns>A log string</returns>
        public override string GetLogDetail()
        {
            return string.Format("InsertTestRunLogEntry({0},{1},{2},{3},{4})", TestRunTaskId, EntryStatus, Url, Message, EntryCreateDate);
        }
    }
}
